/**
 * 
 */
package com.yidin.lsc;

import java.util.List;
import com.yidin.entry.UserLoadCommentListEntry;
import com.yidin.util.NetImageBase;
import com.yidin.util.imageCallback;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author cola
 * 
 */
public class UserLoadCommentListAdapter extends MyBaseAdapter {

	public UserLoadCommentListAdapter(List<UserLoadCommentListEntry> info,
			Context context) {
		super(info, context);
		this.userInfos = info;
	}

	private List<UserLoadCommentListEntry> userInfos;

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.userInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.userInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final int i = position;
		ViewHolder  holder;
		if (convertView == null) {
			View view = LayoutInflater.from(context).inflate(
					R.layout.commetitem, null);
			convertView = view;
			holder = new ViewHolder();
			view.setTag(holder);
			holder.itemame = (TextView) view.findViewById(R.id.adress_name);
			holder.content = (TextView) view.findViewById(R.id.address_im);
			holder.time = (TextView) view.findViewById(R.id.pro_right);
			holder.itemImage = (ImageView) view.findViewById(R.id.pro_gameico);
			final ImageView iv = holder.itemImage;
			Bitmap bm = null;
			if (this.userInfos.get(position).PhotoUrl != null) {// 请求图标
				bm = new NetImageBase().getLogoBitmap(handler, context,
						this.userInfos.get(position).PhotoUrl,
						new imageCallback() {
							public void getImage(Bitmap bm) {
								// TODO Auto-generated method stub
								if (bm != null) {
									iv.setImageBitmap(bm);
									getIsSelected().put(i, bm);
								}
							}
						});

			}
			if (bm != null) {
				iv.setImageBitmap(bm);
				getIsSelected().put(i, bm);
			}
			holder.itemImage = iv;
			convertView.setTag(holder);
		} else {
			ViewHolder vh = (ViewHolder) convertView.getTag();
			if(getIsSelected().get(position) != null)
			vh.itemImage.setImageBitmap(getIsSelected().get(position));
		}
		return convertView;
	}

	private class ViewHolder {
		public TextView itemame;
		public TextView content;
		public TextView time;
		public ImageView itemImage;
	}
}
